package nsu.edu.zsq.controller.sys;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;

import nsu.edu.zsq.bean.Message;
import nsu.edu.zsq.bean.SysUser;
import nsu.edu.zsq.common.JsonData;
import nsu.edu.zsq.common.RequestHolder;
import nsu.edu.zsq.param.PageQuery;
import nsu.edu.zsq.service.sys.MessageService;
import nsu.edu.zsq.service.sys.SysUserService;

/** 
* Description: 管理员用户信息的controller类<br>
*/
@Controller
@RequestMapping("/sys/info")
public class SysUserController {
  
	@Autowired
    private MessageService messageService;
    @Autowired
    private SysUserService sysUserService;
    
    /**
     * 到达管理员的个人信息页面
     * @param model
     * @return String manager/info/manager_info.html
     */
    @RequestMapping("/toInfo")
    public String toInfo(Model model) {
        SysUser sysUser = sysUserService.getSysUser();
        model.addAttribute("sysUser", sysUser);
        return "manager/info/manager_info.html";
    }
    
    /**
     * 修改管理员个人密码
     * @param sysUser
     * @return JsonData
     */
    @RequestMapping("/updatePas")
    @ResponseBody
    public JsonData updatePassword(SysUser sysUser) {
        sysUserService.updatePasswordByPrimaryKey(sysUser);
        return JsonData.success();
    }
    
 
    
    
    /**
     * @param model 
     * @return String manager/manager_welcome.html
     */
    @RequestMapping("/toManager_welcome")
    public String toManager_welcome(Model model) {
        Message message = messageService.getTopMessage();
        model.addAttribute("message", message);
        model.addAttribute("sysUser", RequestHolder.getCurrentSysUser());
        return "manager/manager_welcome.html";
    }
    
    /**
     * @param PageQuery 分页数据
     * @return JsonData
     */
    @RequestMapping("/listMessage")
    @ResponseBody
    public JsonData listMessage(PageQuery pageQuery) {
        PageInfo<Message> listMessage = messageService.listMessageWithPage(pageQuery);
        return JsonData.success(listMessage);
    }
    
    /**
     * @param model 
     * @return String manager/manager_schoolMsg_detail.html
     */
    @RequestMapping("/toMessageDetail")
    public String toMessageDetail(@RequestParam("id")int id, Model model) {
        Message message = messageService.getMessage(id);
        model.addAttribute("message", message);
        return "manager/manager_schoolMsg_detail.html";
    }
}
